package com.zxt.smartplatform.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.zxt.smartplatform.dto.R;
import com.zxt.smartplatform.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/devices")
public class DeviceController {

    private DeviceService deviceService;

    @Autowired
    public void setDeviceService(DeviceService deviceService) {
        this.deviceService = deviceService;
    }

    @PostMapping("/command/{id}/{command}")
    public R sendController(@PathVariable String id, @PathVariable String command) throws JsonProcessingException {
        //向指定的设备发送命令
        deviceService.sendControl(id, command);
        return R.setOK();
    }
}
